const { ccclass, property } = cc._decorator;
import c from "./AudioManager"
import u from "./frameworkManager"
import p from "./EngineUtil"
import d from "./MatchAniCtrl"
import h from "./ObstacleAniCtrl"
import f from "./PropAniCtrl"
import g from "./SkillAniCtrl"
import y from "./TargetAniCtrl"
import m from "./MatchItemPrefabCtrl"
import _ from "./ObstaclePrefabCtrl"
import v from "./PropPrefabCtrl"
import b from "./UiManage"
import C from "./MatchGameData"
import T from "./MatchGameConfig"
import M, { LayerType, ObstacleAllType } from "./ObstacleConfig"
import P from "./BottomBgCtrl"
import S from "./FlyPropellerCtrl"
import w from "./MatchItemCtrl"
import A from "./ObstacleCtrl"
import O from "./PropsCtrl"
import I from "./PageMgr"
import N from "./CandleChoseCtrl"
import E from "./DrillFillInInPutCtrl"
import G from "./EditorBottomItemCtrl"
import k from "./FileMgr"
import D from "./FindPathMgr"
import B from "./FixedRefreshCtrl"
import L from "./LevelEditorDataMgr"
import R from "./SquareEditorItem"
import F from "./TargetEditorItem";
import UiManager from "./UiManage";
import MatchGameConfig from "./MatchGameConfig";

enum s {
    MatchItem = 1,
    PropItem = 2,
    ObstacleItem = 3,
    Null = 4
}

enum x {
    Map = 0,
    Lowest = 1,
    Middle = 2,
    Top = 3
}

enum ItemType {
    MatchItem = 1,
    PropItem = 2,
    ObstacleItem = 3,
    Null = 4
}

enum Difficulty {
    Map = 0,
    Lowest = 1,
    Middle = 2,
    Top = 3
}

var j: number[] = [5, 7, 11, 12, 15, 20, 28];
var V: string[] = ["easy", "middle", "hard", "redEnvelope"];
var W: string[] = ["noNewObstacle", "haveNewObstacle"];

@ccclass
export default class LevelEditorCtrl extends cc.Component {
    @property({ type: cc.EditBox })
    level_input: cc.EditBox = null;

    @property({ type: cc.EditBox })
    steps_input: cc.EditBox = null;

    @property({ type: cc.Node })
    mapColoBlackNode: cc.Node = null;

    @property({ type: cc.Node })
    mapColoGrayNode: cc.Node = null;

    @property({ type: cc.Node })
    obstacleNode_0: cc.Node = null;

    @property({ type: cc.Node })
    obstacleNode_1: cc.Node = null;

    @property({ type: cc.Node })
    obstacleSNode_1: cc.Node = null;

    @property({ type: cc.Node })
    obstacleNode_2: cc.Node = null;

    @property({ type: cc.Node })
    obstacleSNode_2: cc.Node = null;

    @property({ type: cc.Node })
    baseElementNode: cc.Node = null;

    @property({ type: cc.Node })
    propsNode: cc.Node = null;

    @property({ type: cc.Node })
    tagSetNode: cc.Node = null;

    @property({ type: cc.Node })
    pRefreshSitNode: cc.Node = null;

    @property({ type: cc.Node })
    levelConfigNode: cc.Node = null;

    @property({ type: cc.Node })
    gameControlNode: cc.Node = null;

    @property({ type: cc.Node })
    bottomBgParent: cc.Node = null;

    @property({ type: cc.Node })
    lowestParent: cc.Node = null;

    @property({ type: cc.Node })
    middleParents: cc.Node = null;

    @property({ type: cc.Node })
    topParents: cc.Node = null;

    @property({ type: cc.Node })
    icicleNode: cc.Node = null;

    @property({ type: cc.Node })
    choseBottleNode: cc.Node = null;

    @property({ type: cc.Prefab })
    targetPrefab: cc.Prefab = null;

    @property({ type: cc.Node })
    elementPropsNode: cc.Node = null;

    @property({ type: cc.Node })
    fixedRefreshNode: cc.Node = null;

    @property({ type: cc.Node })
    btn_fixed_refresh: cc.Node = null;

    @property({ type: cc.Node })
    btn_import_level: cc.Node = null;

    @property({ type: cc.Node })
    btn_generate_level: cc.Node = null;

    @property({ type: cc.Node })
    btn_preview_level: cc.Node = null;

    @property({ type: cc.Node })
    qrImageNode: cc.Node = null;

    @property({ type: cc.Node })
    qrcode: cc.Node = null;

    @property({ type: cc.Node })
    curtainInputNode: cc.Node = null;

    @property({ type: cc.Node })
    icicleInputNode: cc.Node = null;

    @property({ type: cc.Node })
    levelCategoryNode: cc.Node = null;

    @property({ type: cc.Node })
    newObstacleNode: cc.Node = null;

    @property({ type: cc.Node })
    guideIndexEdit: cc.Node = null;

    @property({ type: cc.Node })
    btn_candle: cc.Node = null;

    @property({ type: cc.Node })
    choseCandleNode: cc.Node = null;

    @property({ type: cc.Node })
    cupHolderChoseNode: cc.Node = null;

    @property({ type: cc.Node })
    drillFillInPutNode: cc.Node = null;

    public bottomPrefab = null;
    public matchItemPrefab = null;
    public propItemPrefab = null;
    public obstacleItemPrefab = null;
    public emptyObstaclePrefab = null;
    public flyPropellerPrefab = null;
    public multiObstacleItem = null;
    public cupboardPlate = null;
    public curtain = null;
    public flyMailPrefab = null;
    public icicle = null;
    public flyPropellerParent = null;

    private async initData(): Promise<void> {
        console.log("游戏初始化----");
        this.bottomPrefab = await UiManager.loaderPrefabInDeepPath("prefabs/bottomPrefab");
        this.matchItemPrefab = await UiManager.loaderPrefabInDeepPath("prefabs/matchItemPrefab");
        this.propItemPrefab = await UiManager.loaderPrefabInDeepPath("prefabs/propPrefab");
        this.obstacleItemPrefab = await UiManager.loaderPrefabInDeepPath("prefabs/obstaclePrefab");
        this.emptyObstaclePrefab = await UiManager.loaderPrefabInDeepPath("prefabs/EmptyObstacleItem");
        this.flyPropellerPrefab = await UiManager.loaderPrefabInDeepPath("prefabs/flyPropellerPrefab");
        this.multiObstacleItem = await UiManager.loaderPrefabInDeepPath("prefabs/multiObstaclePrefab");
        this.cupboardPlate = await UiManager.loaderPrefabInDeepPath("prefabs/CupboardPlate");
        this.curtain = await UiManager.loaderPrefabInDeepPath("prefabs/Curtain");
        this.flyMailPrefab = await UiManager.loaderPrefabInDeepPath("prefabs/flyMailPrefab");
        this.icicle = await UiManager.loaderPrefabInDeepPath("prefabs/Icicle");

        P.ready(this.bottomPrefab, this.bottomBgParent);
        S.ready(this.flyPropellerPrefab, this.flyPropellerParent);
        console.log("游戏初始化2----");
        w.ready(this.matchItemPrefab, this.middleParents);
        // A.ready(this.obstacleItemPrefab, this.emptyObstaclePrefab, this.lowestParent, this.middleParents, this.topParents, this.multiObstacleItem);
        O.ready(this.propItemPrefab, this.middleParents);
        console.log("游戏初始化3----");

        await f.init();
        await g.init();
        await h.init();
        await y.init();
        await d.init();
        this.createMap();
    }


    public onLoad() {
        
        I.init();
        this.addEvent();
        this.setSitItemParentArr();
        this.addButtonEvent();
        this.showOneRadio(this.newObstacleNode, "option_2");
        this.initData();
    };
    public addButtonEvent() {
        this.addMapColorListen();
        this.addChoseItmeListen();
        // this.addChoseBottleListen();
        this.addFixedRefreshListen();
        this.addChoseCandleListen();
    };
    public addChoseCandleListen() {
        this.addButtonListen(this.btn_candle, this.showChoseCandle, this);
    };
    public showChoseCandle() {
        this.choseCandleNode.active = true;
    };
    public importLevel() {
        var e = this;
        u.log("点击导入关卡");
        k.readJsonFile(function (t, a) {
            u.log("导入关卡======", t);
            e.upLoadImpotLevel(t, false);
            e.recoveryImportLevel(t, a);
        });
    };
    public upLoadImpotLevel(e, t) {
        var a = JSON.stringify(e);
        u.log("导入关卡====保存中...\n", e);
        var o = k.downloadFile(a, "experienceMap.json", true);
        this.upload_oss(o, "apkLevelConfig/experienceMap.json", t);
    };
    public levelCategory;
    public haveNewObstce;
    public probabilityDropData;
    public suffix_str;
    public generateLevel(e, t) {
        void 0 === t && (t = false);
        u.log("点击生成关卡");
        var a = this.level_input.getComponent(cc.EditBox).string;
        if (a) if (parseInt(a)) {
            var o = this.steps_input.getComponent(cc.EditBox).string;
            if (o) if (parseInt(o)) if (null != this.levelCategory) if (null != this.haveNewObstce) {
                var i = this.guideIndexEdit.getComponent(cc.EditBox).string;
                if (1 != this.haveNewObstce || i && parseInt(i)) {
                    if (0 == this.haveNewObstce) {
                        i = "0";
                        this.guideIndexEdit.getComponent(cc.EditBox).string = "";
                    }
                    var r = this.getFinalTargetInfo();
                    if (r.length > 4) p.showManageViewToast("目标设置不为4种请检查"); else {
                        this.probabilityDropData = [];
                        this.getPocketbottomData(this.elementPropsNode);
                        this.getPocketbottomData(this.pRefreshSitNode);
                        if (this.checkProbabilityDropFinsh(this.probabilityDropData)) {
                            L.initGameInfo.level = parseInt(a);
                            L.initGameInfo.totalStep = parseInt(o);
                            L.initGameInfo.targetMatchData = r;
                            this.fixedRefreshNode.getComponent(B).clickSure();
                            L.initGameInfo.levelCategory = this.levelCategory;
                            L.initGameInfo.haveNewObstce = this.haveNewObstce;
                            L.initGameInfo.guideIndex = parseInt(i);
                            u.log("关卡生成数据=========", L.initGameInfo);
                            var n = parseInt(a), l = V[this.levelCategory] + "_" + W[this.haveNewObstce], s = "map_" + l + "_level_" + n + ".json";
                            this.suffix_str = "map_" + l + "_level_" + n;
                            u.log("文件名称", s);
                            var c = L.initGameInfo;
                            this.upLoadImpotLevel(c, false);
                            var d = JSON.stringify(c);
                            u.log("保存中...\n", c);
                            var h = k.downloadFile(d, s, t);
                            u.log("保存成功");
                            if (t) {
                                var f = "configLevel/map_" + l + "_level_" + n + ".json";
                                // this.upload_oss(h, f);
                            }
                        } else p.showManageViewToast("兜底刷新配置相加不为100%请检查");
                    }
                } else p.showManageViewToast("障碍物关卡索引不正确");
            } else p.showManageViewToast("没有配置是否有新障碍物"); else p.showManageViewToast("没有配置关卡类型"); else p.showManageViewToast("限定步数填写错误"); else p.showManageViewToast("没有填写限定步数请检查");
        } else p.showManageViewToast("关卡填写错误"); else p.showManageViewToast("没有填写关卡请检查");
    };
    public checkProbabilityDropFinsh(e) {
        if (e) {
            var t = 0;
            e.forEach((e) => {
                t += e.precentNumber;
            });
            return 100 == t;
        }
        u.log("兜底刷新数据获取错误");
    };
    public getFinalTargetInfo() {
        for (var e = this.tagSetNode.children, t = [], a = 0; a < e.length; a++) {
            var o = e[a], i = o.getChildByName("input_count").getComponent(cc.EditBox).string, r = o.getComponent(F);
            if (parseInt(i)) {
                var n = r.squareType, l = null;
                n == s.MatchItem ? l = r.matchType : n == MatchGameConfig.SquareType.PropItem ? l = r.propType : n == s.ObstacleItem && (l = r.obstacleType);
                var c = {
                    squareType: n,
                    itemType: l,
                    tootalCount: parseInt(i),
                    squareTypeStr: r.squareTypeStr
                };
                t.push(c);
            }
        }
        return t;
    };
    public previweLevel() {
        u.log("预览生成关卡");
        this.qrImageNode.active ? this.qrImageNode.active = false : this.generateLevel(null, true);
    };
    public createQrcode() {
        // var e = "https://wm-cd.fingerscloud.com/gameBuild/web-mobile/index.html?suffix_str=" + this.suffix_str;
        // u.log("生成二维码的URL=====", e);
        // var t = this.qrcode.getComponent(cc.Graphics);
        // t.clear();
        // var a = new QRCode(-1, QRErrorCorrectLevel.H);
        // a.addData(e);
        // a.make();
        // t.fillColor = cc.Color.BLACK;
        // for (var o = this.qrImageNode.width / a.getModuleCount(), i = this.qrImageNode.height / a.getModuleCount(), r = 0; r < a.getModuleCount(); r++) for (var n = 0; n < a.getModuleCount(); n++) if (a.isDark(r, n)) {
        //     var l = Math.ceil((n + 1) * o) - Math.floor(n * o), s = Math.ceil((r + 1) * o) - Math.floor(r * o);
        //     t.rect(Math.round(n * o), Math.round(r * i), l, s);
        //     t.fill();
        // }
    };
    public getPocketbottomData(e) {
        for (var t = e.children, a = [], o = 0; o < t.length; o++) {
            var i = t[o], r = i.getComponent(F), n = i.getChildByName("input_count").getComponent(cc.EditBox).string, l = r.squareType, c = null;
            if (l == s.MatchItem) {
                c = r.matchType;
                l = "M";
            } else if (l == MatchGameConfig.SquareType.PropItem) {
                c = r.propType;
                l = "P";
            } else if (l == s.ObstacleItem) {
                c = r.obstacleType;
                l = "O";
            }
            n || (n = 0);
            n = parseInt(n);
            (!parseInt(n) || parseInt(n) <= 0) && (n = 0);
            var u = l + "-" + c;
            "O" == l && (u = r.squareTypeStr);
            var p = {
                squareTypeStr: u,
                precentNumber: n
            };
            this.probabilityDropData.push(p);
            a.push(p);
        }
        L.setProbabilityDropData(this.probabilityDropData);
        return a;
    };
    public addFixedRefreshListen() {
        if (!this.btn_fixed_refresh.getComponent(cc.Button)) {
            this.btn_fixed_refresh.addComponent(cc.Button);
            this.addButtonListen(this.btn_fixed_refresh, this.showFixedRefresh, this);
        }
    };
    public showFixedRefresh() {
        this.fixedRefreshNode.active = true;
    };
    public addMapColorListen() {
        if (!this.mapColoBlackNode.getComponent(cc.Button)) {
            this.mapColoBlackNode.addComponent(cc.Button);
            this.addButtonListen(this.mapColoBlackNode, this.choseNeedPlaceItem, this);
        }
        if (!this.mapColoGrayNode.getComponent(cc.Button)) {
            this.mapColoGrayNode.addComponent(cc.Button);
            this.addButtonListen(this.mapColoGrayNode, this.choseNeedPlaceItem, this);
        }
    };
    public addChoseBottleListen() {
        var e = this.choseBottleNode.getChildByName("btn_sure");
        if (!e.getComponent(cc.Button)) {
            e.addComponent(cc.Button);
            this.addButtonListen(e, this.saveChoseBottleData, this);
        }
        var t = this.choseBottleNode.getChildByName("btn_reset");
        if (!t.getComponent(cc.Button)) {
            t.addComponent(cc.Button);
            this.addButtonListen(t, this.resetBottomData, this);
        }
        for (var a = this.choseBottleNode.getChildByName("bottleNode").children, o = 0; o < a.length; o++) {
            var i = a[o];
            if (!i.getComponent(cc.Button)) {
                i.addComponent(cc.Button);
                this.addButtonListen(i, this.choseBottle, this);
            }
        }
        var r = this.choseBottleNode.getChildByName("colorBottle");
        if (!r.getComponent(cc.Button)) {
            r.addComponent(cc.Button);
            this.addButtonListen(r, this.clickColorbottle, this);
        }
    };
    public choseBottle(e) {
        for (var t = this.choseBottleNode.getChildByName("bottleNode").children, a = 0; a < t.length; a++) {
            var o = t[a], i = o.getChildByName("Editor_select");
            o.name == e.name ? i.active = true : i.active = false;
        }
        this.bottleName = e.name;
    };
    public bottleName;
    public clickBottleCount;
    public hideSelectBottle() {
        for (var e = this.choseBottleNode.getChildByName("bottleNode").children, t = 0; t < e.length; t++){
            e[t].getChildByName("Editor_select").active = false;
        } 
    };
    public clickColorbottle(e) {
        if (this.bottleName) {
            this.clickBottleCount += 1;
            var t = this.choseBottleNode.getChildByName("bottleNode").getChildByName(this.bottleName).getComponent(cc.Sprite).spriteFrame, a = e.children[this.clickBottleCount - 1];
            a.getComponent(cc.Sprite).spriteFrame = t;
            a.name = this.bottleName;
            a.active = true;
            4 == this.clickBottleCount && (e.getComponent(cc.Button).interactable = false);
        } else {
            u.log("没有选择颜色的====");
            p.showManageViewToast("没有选择颜色请选择颜色");
        }
    };
    public saveChoseBottleData() {
        for (var e = this.choseBottleNode.getChildByName("colorBottle").children, t = 0; t < e.length; t++) {
            var a = e[t].name;
            if ("e_item" != a) {
                var o = a.replace(/[^0-9]/gi, "");
                this.choseBottleData += o.toString();
            }
        }
        u.log("瓶子的选择数据", this.choseBottleData);
        if (4 == this.choseBottleData.length) this.setChoseBottleShow(false); else {
            u.log("请检查输入瓶子的个数是否正确");
            p.showManageViewToast("选择瓶子的数量不正确请检查");
        }
    };
    public setChoseBottleShow(e) {
        this.choseBottleNode.active = e;
        this.choseBottleData = e ? "" : this.choseBottleData;
        this.clickBottleCount = 0;
        this.bottleName = null;
        for (var t = this.choseBottleNode.getChildByName("colorBottle"), a = t.children, o = 0; o < a.length; o++) {
            var i = a[o];
            i.name = "e_item";
            i.active = false;
        }
        t.getComponent(cc.Button).interactable = true;
        this.hideSelectBottle();
    };
    public showOneColorSelect(e) {
        for (var t = [this.mapColoBlackNode, this.mapColoGrayNode], a = 0; a < t.length; a++) {
            var o = t[a];
            o.getChildByName("Editor_select").active = e == o.name;
        }
    };
    public closeChoseBottle() {
        this.setChoseBottleShow(false);
    };
    public resetBottomData() {
        this.setChoseBottleShow(true);
        this.choseBottleData = "";
    };
    public clickLevelCategory(e, t) {
        var a = e.currentTarget._name;
        this.levelCategory = parseInt(t);
        this.showOneRadio(this.levelCategoryNode, a);
    };
    public clickHaveNewObstacle(e, t) {
        var a = e.currentTarget._name;
        this.haveNewObstce = parseInt(t);
        this.showOneRadio(this.newObstacleNode, a);
    };
    public showOneRadio(e, t) {
        for (var a = e.children, o = 0; o < a.length; o++) {
            var i = a[o], r = i.getChildByName("common"), n = i.getChildByName("select");
            if (r && n) {
                r.active = i.name != t;
                n.active = i.name == t;
            }
        }
    };
    public addChoseItmeListen() {
        for (var e = 0; e < this.choseItemParentArr.length; e++) for (var t = this.choseItemParentArr[e], a = 0; a < t.childrenCount; a++) {
            var o = t.children[a];
            if (o.getComponent(R) && !o.getComponent(cc.Button)) {
                o.addComponent(cc.Button);
                o.getComponent(cc.Button).transition = 3;
                this.addButtonListen(o, this.choseNeedPlaceItem, this);
            }
        }
    };
    public showOneSelect(e) {
        for (var t = 0; t < this.choseItemParentArr.length; t++) for (var a = this.choseItemParentArr[t], o = 0; o < a.childrenCount; o++) {
            var i = a.children[o], r = i.getChildByName("Editor_select");
            null == e ? r && (r.active = false) : r && (r.active = i == e);
        }
    };
    public choseNeedPlaceItem(e) {
        var t = this.mapColoBlackNode.name, a = this.mapColoGrayNode.name;
        if (t == e.name || a == e.name) {
            this.curChoseLayer = x.Map;
            this.mapColorType = parseInt(e.name.replace(/[^0-9]/gi, ""));
            this.showOneColorSelect(e.name);
        } else {
            this.mapColorType = null;
            this.showOneColorSelect(null);
            var o = e.getComponent(R);
            L.setChoseItem(o);
            if (o) {
                this.curChoseLayer = o.layout;
                var i = -1;
                if (o.squareType == s.ObstacleItem) if (i == ObstacleAllType.Icicle) {
                    this.deal_IcicleInput(true);
                    this.setChoseBottleShow(false);
                    this.setCurtainInputShow(false);
                } else if (i == ObstacleAllType.ColorBottle) {
                    this.setChoseBottleShow(true);
                    this.deal_IcicleInput(false);
                    this.setCurtainInputShow(false);
                } else if (i == ObstacleAllType.curtain) {
                    this.setCurtainInputShow(true);
                    this.deal_IcicleInput(false);
                    this.setChoseBottleShow(false);
                } else if (i == ObstacleAllType.CupHolder) this.cupHolderChoseNode.active = true; else if (i == ObstacleAllType.DrillFill) this.drillFillInPutNode.active = true; else {
                    this.deal_IcicleInput(false);
                    this.setChoseBottleShow(false);
                    this.setCurtainInputShow(false);
                }
            }
        }
        this.showOneSelect(e);
    };
    public setCurtainInputShow(e) {
        this.curtainInputNode.active = e;
        if (e) {
            var t = this.curtainInputNode.getChildByName("hp_input"), a = this.curtainInputNode.getChildByName("height_input"), o = this.curtainInputNode.getChildByName("width_input");
            t.getComponent(cc.EditBox).string = "";
            a.getComponent(cc.EditBox).string = "";
            o.getComponent(cc.EditBox).string = "";
            this.curtainData = {
                hp: null,
                width: null,
                height: null
            };
        }
    };
    public closeCurtainInput() {
        this.setCurtainInputShow(false);
    };
    public clickSureCurtainInput() {
        var e = this.curtainInputNode.getChildByName("hp_input"), t = this.curtainInputNode.getChildByName("height_input"), a = this.curtainInputNode.getChildByName("width_input"), o = parseInt(e.getComponent(cc.EditBox).string), i = parseInt(t.getComponent(cc.EditBox).string), r = parseInt(a.getComponent(cc.EditBox).string);
        if (!o || o < 1) p.showManageViewToast("窗帘血量输入不正确"); else if (i && 0 != i) if (r && 0 != r) {
            this.curtainData.hp = o;
            this.curtainData.width = r;
            this.curtainData.height = i;
            u.log("窗帘的输入数据======", this.curtainData);
            this.setCurtainInputShow(false);
        } else p.showManageViewToast("窗帘宽度输入不正确"); else p.showManageViewToast("窗帘高度输入不正确");
    };
    public deal_IcicleInput(e) {
        this.icicleInputNode.active = e;
        if (e) {
            var t = this.icicleInputNode.getChildByName("size_input"), a = this.icicleInputNode.getChildByName("direction_input");
            t.getComponent(cc.EditBox).string = "";
            a.getComponent(cc.EditBox).string = "";
            this.icicleData = {
                size: null,
                direction: null
            };
        }
    };
    public closeIcicleInput() {
        this.deal_IcicleInput(false);
    };
    public icicleData;
    public clickSureIcicleInput() {
        var e = this.icicleInputNode.getChildByName("size_input"), t = this.icicleInputNode.getChildByName("direction_input"), a = parseInt(e.getComponent(cc.EditBox).string), o = parseInt(t.getComponent(cc.EditBox).string);
        if (!a || a < 2) p.showManageViewToast("冰块长度输入不正确,长度不能小于2"); else if (!o && 0 != o || o > 3) p.showManageViewToast("冰块方向输入不正确"); else {
            this.icicleData.size = a;
            this.icicleData.direction = o;
            u.log("冰块的输入数据======", this.icicleData);
            this.deal_IcicleInput(false);
        }
    };
    public displayMapInfo = [];
    public lowLayerInfo = [];
    public middleLayerInfo = [];
    public topLayerInfo = [];
    public createMap() {
        this.bottomBgParent.removeAllChildren();
        for (var e = 0; e < 9; e++) {
            this.displayMapInfo[e] = [];
            this.lowLayerInfo[e] = [];
            this.middleLayerInfo[e] = [];
            this.topLayerInfo[e] = [];
            for (var t = 0; t < 11; t++) {
                this.displayMapInfo[e][t] = 1;
                this.lowLayerInfo[e][t] = "N";
                this.middleLayerInfo[e][t] = "N";
                this.topLayerInfo[e][t] = "N";
                var a = cc.instantiate(this.bottomPrefab);
                a.x = 0 + e * a.width;
                a.y = 0 - t * a.height;
                a.name = "bottom_" + e + "_" + t;
                this.bottomBgParent.addChild(a);
                a.getComponent(G) || a.addComponent(G);
                a.getComponent(G).initData({
                    row: e,
                    col: t
                });
            }
        }
        L.initMapLayOutData(this.displayMapInfo);
        L.initBottomLayerData(this.lowLayerInfo);
        L.initMiddleLayerData(this.middleLayerInfo);
        L.initTopLayerData(this.topLayerInfo);
    };
    public resetAll() {
        this.displayMapInfo = [];
        this.lowLayerInfo = [];
        this.middleLayerInfo = [];
        this.topLayerInfo = [];
        this.startTime = null;
        this.startPosData = null;
        this.curChoseLayer = null;
        this.choseBottleData = null;
        this.bottleName = null;
        this.clickBottleCount = 0;
        this.showTargetInfo = [];
        this.bottomrefreshTargrtInfo = [];
        this.probabilityDropData = [];
        L.resetGameInfoData();
        this.bottomBgParent.removeAllChildren();
        this.lowestParent.removeAllChildren();
        this.middleParents.removeAllChildren();
        this.topParents.removeAllChildren();
        this.tagSetNode.removeAllChildren();
        this.pRefreshSitNode.removeAllChildren();
        this.resetFixedRefresh();
        this.fixedRefreshNode.getComponent(B).resetData();
        this.updateRightLocation(0, -1);
        this.showOneSelect(null);
        this.mapColoBlackNode.getChildByName("Editor_select").active = false;
        this.deal_IcicleInput(false);
        this.setChoseBottleShow(false);
        this.setCurtainInputShow(false);
        this.showOneColorSelect(null);
        this.level_input.getComponent(cc.EditBox).string = "";
        this.steps_input.getComponent(cc.EditBox).string = "";
        this.levelCategory = null;
        this.haveNewObstce = 0;
        this.showOneRadio(this.levelCategoryNode, null);
        this.showOneRadio(this.newObstacleNode, "option_2");
        this.suffix_str = "";
        this.qrImageNode.active = false;
        this.createMap();
    };
    public resetFixedRefresh() {
        for (var e = this.elementPropsNode.children, t = 0; t < e.length; t++) {
            var a = e[t], o = a.getComponent(F);
            a.getChildByName("input_count").getComponent(cc.EditBox).string = "";
            o.targetCount = 0;
        }
    };
    public addButtonListen(e, t, a, o?) {
        void 0 === o && (o = "click");
        if (e) {
            if (!e.getComponent(cc.Button)) return;
            e.on("click", function () {
                c.getInstance().playMusic(o);
                t && t.bind(a)(e);
            }, a);
        }
    };


    public choseItemParentArr = [];
    public setSitItemParentArr() {
        this.choseItemParentArr = [this.obstacleNode_0, this, this.obstacleNode_1, this.obstacleSNode_1, this.obstacleNode_2, this.obstacleSNode_2, this.baseElementNode, this.propsNode, this.mapColoBlackNode];
    };
    public addEvent() {
        this.levelConfigNode.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.levelConfigNode.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
        this.levelConfigNode.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
        this.levelConfigNode.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCanCel, this);
    };
    public onTouchStart(e) {
        if (null != this.curChoseLayer) {
            var t = this.levelConfigNode.convertToNodeSpaceAR(e.getLocation());
            this.startPosData = this.getTouchBlock(t);
            this.startTime = new Date().getTime();
        }
    };
    public startPosData;
    public startTime;

    public onTouchMove(e) {
        if (null != this.curChoseLayer) {
            var t = this.levelConfigNode.convertToNodeSpaceAR(e.getLocation()), a = this.getTouchBlock(t);
            this.clickBlockItem(a);
        }
    };
    public onTouchEnd(e) {
        null != this.curChoseLayer && this.checkClick(e);
    };
    public onTouchCanCel() {
        null != this.curChoseLayer && u.log("取消=========");
    };
    public checkClick(e) {
        var t = this.levelConfigNode.convertToNodeSpaceAR(e.getLocation()), a = this.getTouchBlock(t);
        if (a && this.startPosData) {
            if (a.row == this.startPosData.row && a.col == this.startPosData.col) {
                var o = this.canDelete(a.row, a.col);
                a.isCanPlace ? this.clickBlockItem(a) : o && this.longClickBlockItem(a);
            }
        } else u.log("触摸结束没有获取到方块坐标数据", a, this.startPosData);
    };
    public canDelete(e, t) {
        var a = L.getPerLayerCanPlace(e, t), o = a[0], i = a[1], r = a[2], n = a[3], l = true;
        0 == o && (l = this.curChoseLayer == x.Map);
        this.curChoseLayer == x.Map ? 0 != r && 0 != n && 0 != i || (l = false) : this.curChoseLayer == x.Lowest ? 0 != r && 0 != n || (l = false) : this.curChoseLayer == x.Middle ? 0 == n && (l = false) : this.curChoseLayer == x.Top && (l = true);
        return l;
    };
    public curChoseLayer;
    public mapColorType;
    public clickBlockItem(e) {
        if (e) {
            var t = e.isCanPlace;
            if (t) if (this.curChoseLayer == x.Map) {
                var a = this.getBottomCNode(e.row, e.col);
                a && a.sitCanPlaceState(this.mapColorType);
            } else {
                var o = L.getChoseItem();
                if (!o) {
                    u.log("选择的item为空");
                    return;
                }
                var i, r = e.row, n = e.col, l = [this.lowestParent, this.middleParents, this.topParents][this.curChoseLayer - 1], c = o.squareType, d = o.layout;
                u.log("当前item的数据=====", e);
                u.log("当前选择item的数据 ===layout", d);
                if (!t) {
                    u.log("当前层级" + d + "不可以放置");
                    p.showManageViewToast("当前层级" + d + "不可以放置");
                    return;
                }
                i = this.getInitItemStr(o, e);
                u.log("当前选择item的初始化数据数据 ===位置 i====j", r, n);
                u.log("当前选择item的初始化数据数据 ===str", i);
                if (!i) {
                    u.log("选择的item初始化数据不正确");
                    return;
                }
                o.setInitStr(i);
                if (this.curChoseLayer == x.Lowest) {
                    this.createEditorBottomSquareItem(r, n, i, l);
                    var h = l.children[l.children.length - 1];
                    if (!h) {
                        u.log("底层没有添加上子节点请检查");
                        return;
                    }
                    h.name = "lowestLayer_" + r + "_" + n;
                    L.updateBottomData(r, n, i);
                } else if (this.curChoseLayer == x.Middle) {
                    if (c == s.MatchItem || c == MatchGameConfig.SquareType.PropItem) {
                        this.createEditorMiddleSquareItem(r, n, i, l);
                        var f = l.children[l.children.length - 1];
                        if (!f) {
                            u.log("中层没有添加上子节点请检查");
                            return;
                        }
                        var g = f.getComponent(m), y = f.getComponent(v);
                        g && f.removeComponent(m);
                        y && f.removeComponent(v);
                        f.name = "middleLayer_" + r + "_" + n + "-" + i;
                        L.updateMiddleData(r, n, i);
                    } else if (c == s.ObstacleItem) {
                        this.createEditorMiddleSquareItem(r, n, i, l);
                        var b = l.children[l.children.length - 1];
                        if (!b) {
                            u.log("中层没有添加上障碍物节点请检查");
                            return;
                        }
                        b.getComponent(_) && b.removeComponent(_);
                        b.name = "middleLayer_" + r + "_" + n + "-" + i;
                        L.updateMiddleData(r, n, i);
                    }
                } else if (this.curChoseLayer == x.Top) {
                    this.createEditorTopSquareItem(r, n, i, l);
                    var C = l.children[l.children.length - 1];
                    if (!C) {
                        u.log("顶层没有添加上障碍物节点请检查");
                        return;
                    }
                    C.getComponent(_) && C.removeComponent(_);
                    C.name = "topLayer_" + r + "_" + n + "-" + i;
                    L.updateTopData(r, n, i);
                }
                this.updateTagShow(o);
            }
        } else u.log("没有获取到行列信息");
    };
    public updateTagShow(e) {
        var t = e.squareType, a = null, o = e.squareTypeStr;
        t == s.MatchItem ? a = e.matchType : t == MatchGameConfig.SquareType.PropItem ? a = e.propType : t == s.ObstacleItem && (a = ObstacleAllType);
        this.addTagItem(t, a, o);
    };
    public addTagItem(e, t, a) {
        void 0 === a && (a = null);
        if (e == s.MatchItem) this.createMatchTargetItem(t, this.showTargetInfo, this.tagSetNode, a); else if (e == MatchGameConfig.SquareType.PropItem); else if (e == s.ObstacleItem) if (t == ObstacleAllType.MagicHat) this.createMatchTargetItem(5, this.showTargetInfo, this.tagSetNode); else {
            this.onCreateObstacle(t, this.showTargetInfo, this.tagSetNode, true, a);
            -1 !== j.indexOf(t) && this.onCreateObstacle(t, this.bottomrefreshTargrtInfo, this.pRefreshSitNode, false, a);
        }
        this.updateTagItemPos(this.tagSetNode);
        this.updateTagItemPos(this.pRefreshSitNode);
    };
    public updateTagItemPos(e) {
        e || u.log("更新的节点父节点不存在");
        for (var t = e.children, a = 0; a < t.length; a++) {
            var o = t[a], i = Math.floor(a / 10), r = a % 10;
            i % 10 == 0 && 0 != i && (i -= 1);
            0 == r && 0 != r && (r = 10);
            var n = o.getBoundingBox().size, l = 40 + 40 * r + .5 * n.width * r + 10 * r, s = -40 - -40 * i - n.height * i - 50 * i;
            o.x = l;
            o.y = s;
        }
        var c = this.getTagItemEndCol(this.tagSetNode), p = this.getTagItemEndCol(this.pRefreshSitNode);
        this.updateRightLocation(c, p);
    };
    public getTagItemEndCol(e) {
        if (e) {
            var t = e.childrenCount - 1, a = Math.floor(t / 10);
            a % 10 == 0 && 0 != a && (a -= 1);
            return a;
        }
        u.log("获取最后一个");
    };
    public updateRightLocation(e, t) {
        0 != e && e % 9 == 0 ? e = e : e += 1;
        0 != t && t % 9 == 0 ? t = t : t += 1;
        var a = this.targetPrefab.data.getBoundingBox().size, o = (e = 0 == e ? 1 : e) * a.height;
        this.elementPropsNode.y = this.tagSetNode.parent.y - o - 50;
        this.pRefreshSitNode.parent.y = this.elementPropsNode.y - 150;
        var i = t * a.height;
        this.levelConfigNode.y = this.pRefreshSitNode.parent.y - i - 50;
        this.gameControlNode.y = this.levelConfigNode.y - this.levelConfigNode.height - 100;
    };
    public isCheckColorBoxCanPlace(e, t, a) {
        var o = {
            b_row: a.row,
            b_col: a.col,
            end_row: a.row + e,
            end_col: a.col + t
        };
        if (o.end_row > 8 || o.end_col > 10 || o.end_row < 0 || o.end_col < 0) {
            u.log("配置的木箱超过界面了请检查========");
            return null;
        }
        var i = this.findCenterSquare(o);
        u.log("找到的中间方块的数据======", i);
        var r = this.checkSquareCanPlace(i);
        r && L.setRelationData(i, a);
        return r;
    };
    public choseBottleData;
    public getColorBoxStr(e, t) {
        if (!this.choseBottleData) {
            p.showManageViewToast("没有选择瓶子");
            return null;
        }
        return this.isCheckColorBoxCanPlace(1, 1, t) ? "O-" + ObstacleAllType + "_" + this.choseBottleData : null;
    };
    public getInitItemStr(e, t) {
        var a = null, o = e.squareType, i;
        o == s.MatchItem ? a = e.getmatchItemInfo() : o == s.ObstacleItem ? a = i == ObstacleAllType.Icicle ? this.getIcicleInput(e, t) : i == ObstacleAllType.ColorBottle ? this.getColorBoxStr(e, t) : i == ObstacleAllType.cupboard || i == ObstacleAllType.GrassLand || i == ObstacleAllType.SafeBox || i == ObstacleAllType.BirdNest ? this.getFixedObstracalStr(e, t) : i == ObstacleAllType.curtain ? this.getCurtainInput(e, t) : i == ObstacleAllType.Candlebox ? this.getCandleBoxInitStr(e, t) : i == ObstacleAllType.CupHolder ? this.getCupHolderStr(e, t) : i == ObstacleAllType.DrillFill ? this.getDrillFillInitStr(e, t) : e.getObstacleInfo() : o == MatchGameConfig.SquareType.PropItem && (a = e.getPropInfo());
        return a;
    };
    public getDrillFillInitStr(e, t) {
        var a = ObstacleAllType, o = this.drillFillInPutNode.getComponent(E).getDrillfillData();
        if (!o) {
            p.showManageViewToast("钻头数据没有设置请设置");
            return null;
        }
        var i = o.hp, r = o.color, n = o.dir;
        if (!this.isCheckIcicleCanSit(2, n, t)) {
            u.log("当前位置不可以放置钻头");
            p.showManageViewToast("当前位置不可以放置钻头");
            return null;
        }
        return "O-" + a + "_" + i + "_" + r + "_" + n;
    };
    public getCupHolderStr(e, t) {
        var a = t.init_str;
        if (!a) {
            p.showManageViewToast("没有设置茶杯数据");
            return null;
        }
        var o = D.getPosDataByStr(a);
        if (!L.isCanPlaceCupHolder(o)) {
            p.showManageViewToast("当前位置不可以放置茶杯");
            return null;
        }
        o.shift();
        o.forEach((e) => {
            L.updateMiddleData(e.row, e.col, "E");
        });
        return t.init_str;
    };
    public isCheckCurtainCanPlace(e, t, a) {
        var o = {
            b_row: a.row,
            b_col: a.col,
            end_row: a.row + e,
            end_col: a.col + t
        };
        if (o.end_row > 8 || o.end_col > 10 || o.end_row < 0 || o.end_col < 0) {
            u.log("配置的窗帘超过界面了请检查========");
            return null;
        }
        var i = this.findCenterSquare(o, true);
        u.log("找到的顶部可以放置的数据======", i);
        var r = this.checkSquareCanPlace(i, true);
        r && L.setRelationData(i, a, true);
        return r;
    };
    public getFixedObstracalStr(e, t) {
        return this.isCheckColorBoxCanPlace(1, 1, t) ? e.getObstacleInfo() : null;
    };
    public curtainData;
    public getCurtainInput(e, t) {
        var a = ObstacleAllType, o = e.obstacleColor, i = this.curtainData.hp, r = this.curtainData.width, n = this.curtainData.height;
        if (!i || i < 1) {
            p.showManageViewToast("窗帘血量输入不正确");
            return null;
        }
        if (!n || 0 == n) {
            p.showManageViewToast("窗帘高度输入不正确");
            return null;
        }
        if (!r || 0 == r) {
            p.showManageViewToast("窗帘宽度输入不正确");
            return null;
        }
        if (!this.isCheckCurtainCanPlace(r - 1, n - 1, t)) {
            u.log("当前位置不可以放置窗帘");
            p.showManageViewToast("当前位置不可以放置窗帘");
            return null;
        }
        return "O-" + a + "_" + i + "_" + o + "_" + r + "_" + n;
    };
    public getCandleBoxInitStr(e, t) {
        var a = ObstacleAllType, o = this.choseCandleNode.getComponent(N).getChoseCandleColor();
        if (!o) {
            p.showManageViewToast("没有选择蜡烛盒子颜色");
            return null;
        }
        if (!this.isCheckColorBoxCanPlace(1, 1, t)) {
            p.showManageViewToast("当前位置不可以放置蜡烛盒子");
            return null;
        }
        return "O-" + a + "_" + o;
    };
    public getIcicleInput(e, t) {
        var a = ObstacleAllType, o = this.icicleData.size, i = this.icicleData.direction;
        if (!o || o < 2) p.showManageViewToast("冰块长度输入不正确,长度不能小于2"); else {
            if (!(!i && 0 != i || i > 3)) return this.isCheckIcicleCanSit(o, i, t) ? "O-" + a + "_" + o + "_" + i : null;
            p.showManageViewToast("冰块方向输入不正确");
        }
    };
    public isCheckIcicleCanSit(e, t, a) {
        var o = this.getStartEndPosData(e, t, a);
        if (!o) return null;
        u.log("起始的坐标======数据", o);
        var i = this.findCenterSquare(o);
        u.log("找到的中间方块的数据======", i);
        var r = this.checkSquareCanPlace(i);
        r && L.setRelationData(i, a);
        return r;
    };
    public getStartEndPosData(e, t, a) {
        var o = a.row, i = a.col, r = null, n = null;
        e -= 1;
        if (0 == t) {
            n = i - e;
            r = o;
        } else if (1 == t) {
            r = o + e;
            n = i;
        } else if (2 == t) {
            n = i + e;
            r = o;
        } else if (3 == t) {
            r = o - e;
            n = i;
        }
        var l = o, s = i;
        if (o > r) {
            o = r;
            r = l;
        }
        if (i > n) {
            i = n;
            n = s;
        }
        if (r > 8 || n > 10 || r < 0 || n < 0 || i < 0 || o < 0 || i > 10 || o > 8) {
            u.log("配置的冰块超过界面了请检查========");
            p.showManageViewToast("配置的冰块超过界面了请检查");
            return null;
        }
        return {
            b_row: o,
            b_col: i,
            end_row: r,
            end_col: n
        };
    };
    public setSquareState(e, t, a) {
        void 0 === t && (t = false);
        for (var o = 0; o < e.length; o++) {
            var i = e[o];
            if (a.row == i.row && a.col == i.col) u.log("不设置当前的========="); else {
                i.isNeedPlace = t;
                i.bg.active = !t;
                i.updateData();
            }
        }
    };
    public findCenterSquare(e, t?) {
        void 0 === t && (t = false);
        var a = L.initGameInfo.middleSquareData;
        t && (a = L.initGameInfo.topSquareData);
        for (var o = [], i = e.b_row, r = e.b_col, n = e.end_row, l = e.end_col, s = 0; s < a.length; s++) for (var c = a[s], u = 0; u < c.length; u++) if (s >= i && s <= n && u >= r && u <= l) {
            var p = {
                row: s,
                col: u
            };
            o.push(p);
        }
        return o;
    };
    public checkSquareCanPlace(e, t?) {
        void 0 === t && (t = false);
        if (!e) {
            u.log("获取的中间方块不存在");
            return false;
        }
        u.log("获取中间方块数据", e);
        var a = L.checkBottomCanPlace(e);
        u.log("bottomCanPlace", a);
        if (!a) return false;
        var o = L.checkMiddleCanPlace(e);
        t && (o = L.checkTopCanPlace(e));
        u.log("middleCanPlace", o);
        return o;
    };
    public longClickBlockItem(e) {
        var t = this;
        if (this.curChoseLayer == x.Map) {
            var a = this.getBottomCNode(e.row, e.col);
            if (a) {
                if (a.sitState != this.mapColorType) {
                    p.showManageViewToast("选择同种类型取消");
                    return;
                }
                a.sitCanPlaceState(1);
            }
        } else {
            var o = this.getBottomCNode(e.row, e.col);
            if (o && 1 != o.sitState) {
                p.showManageViewToast("当前不可以放置");
                return;
            }
            var i = L.getChoseItem();
            if (!i) {
                u.log("没有选择的可放置的元素");
                return;
            }
            var r = i.squareType, n = i.matchType, l = i.propType, c;
            if (this.curChoseLayer == x.Lowest) {
                var d = this.getLowTouchNode(e.row, e.col);
                if (d) {
                    L.updateBottomData(e.row, e.col, "N");
                    d.removeFromParent();
                    C.getTargetObstacleArrByObstacle(c).forEach((e) => {
                        t.updateShowTagetInfo(r, e, false, false, t.showTargetInfo, t.tagSetNode);
                    });
                }
            } else if (this.curChoseLayer == x.Middle) {
                var h = L.initGameInfo.middleSquareData[e.row][e.col];
                if (null == (E = this.getChoseType(h)).pType || null == E.sType) {
                    u.log("删除操作返回的数据类型数据不正确");
                    return;
                }
                var f = E.pType, g = E.sType;
                if (f != r) {
                    u.log("需要选择同一种类型才可以取消");
                    p.showManageViewToast("需要选择同一种类型才可以取消");
                    return;
                }
                if (r == s.MatchItem || r == MatchGameConfig.SquareType.PropItem) {
                    if (r == s.MatchItem && g != n) return;
                    if (r == MatchGameConfig.SquareType.PropItem && g != l) return;
                    var y = L.initGameInfo.middleSquareData[e.row][e.col], m = this.getMiddleTouchNode(e.row, e.col, y);
                    if (m) {
                        L.updateMiddleData(e.row, e.col, "N");
                        m.removeFromParent();
                        r == s.MatchItem && this.updateShowTagetInfo(r, n, false, false, this.showTargetInfo, this.tagSetNode);
                    }
                } else if (r == s.ObstacleItem) {
                    if (g != c) {
                        u.log("需要选择同一种类型才可以取消");
                        p.showManageViewToast("需要选择同一种类型才可以取消");
                        return;
                    }
                    -1 !== j.indexOf(c) && C.getTargetObstacleArrByObstacle(c, false).forEach((e) => {
                        t.updateShowTagetInfo(r, e, false, false, t.bottomrefreshTargrtInfo, t.pRefreshSitNode, false);
                    });
                    if (c == ObstacleAllType.Icicle || c == ObstacleAllType.DrillFill) {
                        var _ = (k = (y = L.initGameInfo.middleSquareData[e.row][e.col]).split("_"))[1], v = k[2];
                        if (c == ObstacleAllType.DrillFill) {
                            _ = 2;
                            v = k[3];
                        }
                        var b = this.getStartEndPosData(parseInt(_), parseInt(v), e), P = this.findCenterSquare(b);
                        L.clearRelationData(P);
                        var S = this.getMiddleTouchNode(e.row, e.col, y);
                        if (S) {
                            S.removeFromParent();
                            C.getTargetObstacleArrByObstacle(c).forEach((e) => {
                                t.updateShowTagetInfo(r, e, false, false, t.showTargetInfo, t.tagSetNode);
                            });
                        }
                    } else if (c == ObstacleAllType.ColorBottle || c == ObstacleAllType.cupboard || c == ObstacleAllType.GrassLand || c == ObstacleAllType.SafeBox || c == ObstacleAllType.Candlebox || c == ObstacleAllType.BirdNest) {
                        var w = L.initGameInfo.middleSquareData[e.row][e.col];
                        b = {
                            b_row: e.row,
                            b_col: e.col,
                            end_row: e.row + 1,
                            end_col: e.col + 1
                        }, P = this.findCenterSquare(b);
                        L.clearRelationData(P);
                        var A = this.getMiddleTouchNode(e.row, e.col, w);
                        if (A) {
                            A.removeFromParent();
                            C.getTargetObstacleArrByObstacle(c).forEach((e) => {
                                t.updateShowTagetInfo(r, e, false, false, t.showTargetInfo, t.tagSetNode, true, c);
                            });
                        }
                    } else if (c == ObstacleAllType.CupHolder) {
                        y = L.initGameInfo.middleSquareData[e.row][e.col];
                        var O = D.getPosDataByStr(y), I = D.getTotalCountByStr(y);
                        L.clearRelationData(O);
                        if (G = this.getMiddleTouchNode(e.row, e.col, y)) {
                            G.removeFromParent();
                            C.getTargetObstacleArrByObstacle(c).forEach((e) => {
                                t.updateShowTagetInfo(r, e, false, false, t.showTargetInfo, t.tagSetNode, true, null, I);
                            });
                        }
                    } else {
                        var N = L.initGameInfo.middleSquareData[e.row][e.col];
                        if (G = this.getMiddleTouchNode(e.row, e.col, N)) {
                            L.updateMiddleData(e.row, e.col, "N");
                            G.removeFromParent();
                            c == ObstacleAllType.MagicHat ? this.updateShowTagetInfo(s.MatchItem, T.MatchItemType.purpleGem, false, false, this.showTargetInfo, this.tagSetNode) : C.getTargetObstacleArrByObstacle(c).forEach((e) => {
                                t.updateShowTagetInfo(r, e, false, false, t.showTargetInfo, t.tagSetNode);
                            });
                        }
                    }
                }
            } else if (this.curChoseLayer == x.Top) {
                var E;
                h = L.initGameInfo.topSquareData[e.row][e.col], f = (E = this.getChoseType(h)).pType,
                    g = E.sType;
                if (null == f || null == g) return;
                if (f != r || g != c) {
                    u.log("需要选择同一种类型才可以取消");
                    p.showManageViewToast("需要选择同一种类型才可以取消");
                    return;
                }
                if (c == ObstacleAllType.Honey) {
                    N = L.initGameInfo.topSquareData[e.row][e.col];
                    if (G = this.getTopTouchNode(e.row, e.col, N)) {
                        L.updateTopData(e.row, e.col, "N");
                        G.removeFromParent();
                        this.updateShowTagetInfo(r, c, false, false, this.showTargetInfo, this.tagSetNode);
                    }
                } else if (c == ObstacleAllType.curtain) {
                    N = L.initGameInfo.topSquareData[e.row][e.col];
                    var G = this.getTopTouchNode(e.row, e.col, N), k = N.split("_"), B = parseInt(k[k.length - 2]), R = parseInt(k[k.length - 1]);
                    b = {
                        b_row: e.row,
                        b_col: e.col,
                        end_row: e.row + B - 1,
                        end_col: e.col + R - 1
                    }, P = this.findCenterSquare(b, true);
                    L.clearRelationData(P, true);
                    if (G) {
                        L.updateTopData(e.row, e.col, "N");
                        G.removeFromParent();
                        this.updateShowTagetInfo(r, c, false, false, this.showTargetInfo, this.tagSetNode);
                    }
                }
            }
        }
    };
    public getChoseType(e) {
        if (e) {
            var t = {
                pType: null,
                sType: null
            }, a = this.getPressType(e[0]), o = e.indexOf("-"), i = e.indexOf("_"), r = true;
            if (-1 == i) {
                r = false;
                i = e.length;
                o = o - 1 <= 0 ? 0 : o - 1;
            }
            var n = e.substr(o + 1, i - o - 1), l = parseInt(n);
            if (!r) {
                n = n.split("-");
                l = parseInt(n[1]);
            }
            t.pType = a;
            t.sType = l;
            return t;
        }
        u.log("获取的初始化类型不正确请检查");
    };
    public getPressType(e) {
        var t = null;
        "M" == e ? t = 1 : "P" == e ? t = 2 : "O" == e ? t = 3 : "N" == e ? t = 4 : "E" == e && (t = 5);
        return t;
    };
    public getTopTouchNode(e, t, a) {
        var o = "topLayer_" + e + "_" + t + "-" + a;
        return this.topParents.getChildByName(o);
    };
    public getMiddleTouchNode(e, t, a) {
        var o = "middleLayer_" + e + "_" + t + "-" + a;
        return this.middleParents.getChildByName(o);
    };
    public getLowTouchNode(e, t) {
        var a = "lowestLayer_" + e + "_" + t;
        return this.lowestParent.getChildByName(a);
    };
    public getBottomCNode(e, t) {
        var a = "bottom_" + e + "_" + t, o = this.bottomBgParent.getChildByName(a);
        return o && o.getComponent(G) ? o.getComponent(G) : null;
    };
    public getTouchBlock(e) {
        if (!e) {
            u.log("触摸点不存在=====请检查");
            return null;
        }
        var t = e.x, a = e.y, o = Math.floor(Math.abs(t) / 78), i = Math.floor(Math.abs(a) / 78);
        if (o > 8 || o < 0 || i > 10 || i < 0) {
            u.log("超出触摸范围");
            return null;
        }
        var r = {
            row: o,
            col: i,
            isCanPlace: true
        }, n = L.getPerLayerCanPlace(o, i), l = n[0], s = n[1], c = n[2], p = n[3];
        if (0 == l) {
            r.isCanPlace = false;
            return r;
        }
        if (this.curChoseLayer == x.Map) {
            if (0 == s || 0 == c || 0 == p) {
                r.isCanPlace = false;
                return r;
            }
        } else if (this.curChoseLayer == x.Lowest) {
            if (0 == s || 0 == c || 0 == p) {
                r.isCanPlace = false;
                return r;
            }
        } else if (this.curChoseLayer == x.Middle) {
            if (0 == c || 0 == p) {
                r.isCanPlace = false;
                return r;
            }
        } else if (this.curChoseLayer == x.Top && 0 == p) {
            r.isCanPlace = false;
            return r;
        }
        return r;
    };
    public createEditorTopSquareItem(e, t, a, o) {
        var i = a.split("-"), r = i[0], n = i[1];
        r == T.SquareType.ObstacleItem && A.createObstacleItem(e, t, n, LayerType.Top, o);
    };
    public createEditorMiddleSquareItem(e, t, a, o) {
        var i = a.split("-"), r = i[0], n = i[1];
        r == T.SquareType.MatchItem ? this.createMatchItem(e, t, Number(n)) : r == T.SquareType.PropItem ? this.createPropItem(e, t, Number(n)) : r == T.SquareType.ObstacleItem ? A.createObstacleItem(e, t, n, LayerType.Lowest, o) : r == T.SquareType.Null ? u.log("---该地点为空--", e, t) : u.log("---配表报错--", r, n);
    };
    public createEditorBottomSquareItem(e, t, a, o) {
        var i = a.split("-"), r = i[0], n = i[1];
        r == T.SquareType.ObstacleItem && A.createObstacleItem(e, t, n, LayerType.Lowest, o);
    };
    public createMatchItem(e, t, a) {
        w.createMatchItem(e, t, a);
    };
    public createPropItem(e, t, a) {
        O.createPropItem(e, t, a);
    };
    public createObstacleTargetItem(e, t, a, o, i, r) {
        void 0 === o && (o = null);
        void 0 === i && (i = 0);
        var n, l = L.getChoseItem();
        n = null == o ? l.squareTypeStr : o;
        var c = cc.instantiate(this.targetPrefab), u = e == T.TargetObstacleType.CupboardPlate ? 10 : 1;
        e == T.TargetObstacleType.Candlebox ? u = 8 : r == T.TargetObstacleType.BirdNest ? 0 == i ? u = 3 : 1 == i && (u = 1) : r == T.TargetObstacleType.CupHolder && (u = D.getTotalCountByStr(n));
        c.getComponent(F).init({
            squareType: s.ObstacleItem,
            itemType: e,
            tootalCount: u,
            squareTypeStr: n,
            index: i
        });
        t.push({
            targetSquareType: s.ObstacleItem,
            itemType: e,
            targetCount: u,
            index: i
        });
        a.addChild(c);
        r == T.TargetObstacleType.CupHolder ? this.updateShowTagetInfo(s.ObstacleItem, e, true, true, t, a, true, null, u) : this.updateShowTagetInfo(s.ObstacleItem, e, true, true, t, a);
    };
    public createMatchTargetItem(e, t, a, o?) {
        void 0 === o && (o = null);
        for (var i = 0; i < t.length; i++) {
            var r = t[i].itemType, n = t[i].targetSquareType;
            if (r == e && n == MatchGameConfig.SquareType.MatchItem) {
                t[i].targetCount += 1;
                this.updateShowTagetInfo(n, r, true, true, t, a);
                u.log("该目标已存在");
                return;
            }
        }
        t.push({
            targetSquareType: s.MatchItem,
            itemType: e,
            targetCount: 1
        });
        var l = L.getChoseItem();
        null == o && l.squareTypeStr;
        var c = cc.instantiate(this.targetPrefab);
        c.getComponent(F).init({
            squareType: s.MatchItem,
            itemType: e,
            tootalCount: 1,
            squareTypeStr: o
        });
        a.addChild(c);
        this.updateShowTagetInfo(s.MatchItem, e, true, true, t, a);
    };
    public createPropTargetItem(e, t, a) {
        for (var o = 0; o < t.length; o++) {
            var i = t[o].itemType, r = t[o].targetSquareType;
            if (i == e && r == MatchGameConfig.SquareType.PropItem) {
                t[o].targetCount += 1;
                this.updateShowTagetInfo(r, i, true, true, t, a);
                u.log("该目标已存在");
                return;
            }
        }
        t.push({
            targetSquareType: MatchGameConfig.SquareType.PropItem,
            itemType: e,
            targetCount: 1
        });
        var n = cc.instantiate(this.targetPrefab);
        n.getComponent(F).init({
            squareType: MatchGameConfig.SquareType.PropItem,
            itemType: e,
            tootalCount: 1
        });
        a.addChild(n);
        this.updateShowTagetInfo(MatchGameConfig.SquareType.PropItem, e, true, true, t, a);
    };
    public onCreateObstacle(e, t, a, o, i) {
        var r = this;
        void 0 === o && (o = true);
        void 0 === i && (i = null);
        var n = C.getTargetObstacleArrByObstacle(e, o);
        n.length <= 0 || n.forEach(function (n, l) {
            if (0 == t.length) r.createObstacleTargetItem(n, t, a, i, l, e); else if (r.isHaveSameType(t, n)) if (n == T.TargetObstacleType.CupHolder) {
                var c = D.getTotalCountByStr(i);
                r.updateShowTagetInfo(s.ObstacleItem, n, true, false, t, a, o, e, c);
            } else r.updateShowTagetInfo(s.ObstacleItem, n, true, false, t, a, o, e); else r.createObstacleTargetItem(n, t, a, i, l, e);
        });
    };
    public isHaveSameType(e, t) {
        for (var a = 0; a < e.length; a++) {
            var o = e[a].itemType, i = e[a].targetSquareType;
            if (o == t && i == s.ObstacleItem) return true;
        }
        return false;
    };
    public updateTagCount(e, t, a, o, i) {
        void 0 === i && (i = true);
        var r = this.getTagNodeByType(e, t, o);
        if (r) {
            var n = r.targetCount, l = r.node;
            if (0 == n) {
                var s = this.getTagInfoIndex(e, t, a);
                if (-1 != s) {
                    a.splice(s, 1);
                    l.removeFromParent();
                    this.updateTagItemPos(this.tagSetNode);
                    this.updateTagItemPos(this.pRefreshSitNode);
                }
            } else l.getChildByName("input_count").getComponent(cc.EditBox).string = n + "";
        } else u.log("获取的目标节点不存在=======");
    };
    public getTagNodeByType(e, t, a) {
        for (var o = a.children, i = 0; i < o.length; i++) {
            var r = o[i].getComponent(F), n = r.targetInfo;
            if (n.squareType == e && n.itemType == t) return r;
        }
        return null;
    };
    public updateShowTagetInfo(e, t, a, o, i, r, n?, l?, c?) {
        void 0 === o && (o = false);
        void 0 === n && (n = true);
        void 0 === l && (l = null);
        void 0 === c && (c = 0);
        for (var u = 0; u < i.length; u++) {
            var p = i[u].itemType, d = i[u].targetSquareType, h = i[u].index;
            if (p == t && d == e) {
                o || (a ? d == s.ObstacleItem && t == T.TargetObstacleType.CupboardPlate ? i[u].targetCount += 10 : d == s.ObstacleItem && t == T.TargetObstacleType.Candlebox ? i[u].targetCount += 8 : d == s.ObstacleItem && l && l == T.TargetObstacleType.BirdNest ? 0 == h ? i[u].targetCount += 3 : 1 == h && (i[u].targetCount += 1) : d == s.ObstacleItem && t == T.TargetObstacleType.CupHolder ? i[u].targetCount += c : i[u].targetCount += 1 : d == s.ObstacleItem && t == T.TargetObstacleType.CupboardPlate ? i[u].targetCount -= 10 : d == s.ObstacleItem && t == T.TargetObstacleType.Candlebox ? i[u].targetCount -= 8 : d == s.ObstacleItem && l && l == T.TargetObstacleType.BirdNest ? 0 == h ? i[u].targetCount -= 3 : 1 == h && (i[u].targetCount -= 1) : d == s.ObstacleItem && t == T.TargetObstacleType.CupHolder ? i[u].targetCount -= c : i[u].targetCount -= 1);
                var f = this.getTagNodeByType(d, p, r);
                if (f) {
                    f.targetCount = i[u].targetCount;
                    this.updateTagCount(d, p, i, r, n);
                }
            }
        }
    };
    public getTagInfoIndex(e, t, a) {
        for (var o = 0; o < a.length; o++) {
            var i = a[o].itemType, r = a[o].targetSquareType;
            if (i == t && r == e) return o;
        }
        return -1;
    };
    public upload_oss(e, t, a) {
        // void 0 === a && (a = true);
        // var o = new OSS({
        //     region: "oss-cn-beijing",
        //     accessKeyId: "LTAI4GH6bYkSs5mNt6VT74t8",
        //     accessKeySecret: "zHm8mGA0ZUoVPK2XfhNP3PBSBvJuqE",
        //     bucket: "worldmatch-file"
        // }), i = this;
        // o.multipartUpload(t, e).then( (e) => {
        //     if (a) {
        //         i.qrImageNode.active = true;
        //         i.createQrcode();
        //     }
        //     u.log("上传成功", e);
        // }).catch( (e) => {
        //     u.log("上传失败", e);
        // });
    };
    public recoveryImportLevel(e, t) {
        if (e) {
            this.resetAll();
            var a = JSON.parse(e);
            L.updateGameInfoData(a);
            var o = L.initGameInfo;
            this.level_input.getComponent(cc.EditBox).string = o.level + "";
            this.steps_input.getComponent(cc.EditBox).string = o.totalStep + "";
            this.levelCategory = o.levelCategory;
            this.haveNewObstce = o.haveNewObstce;
            if (!this.levelCategory && !this.levelCategory) {
                var i = t.split("_");
                this.levelCategory = V.indexOf(i[1]);
                this.haveNewObstce = W.indexOf(i[2]);
            }
            if (-1 === this.levelCategory && -1 === this.haveNewObstce) {
                this.levelCategory = null;
                this.haveNewObstce = null;
                this.showOneRadio(this.levelCategoryNode, null);
                this.showOneRadio(this.newObstacleNode, null);
            } else {
                this.showOneRadio(this.levelCategoryNode, "option_" + (this.levelCategory + 1));
                var r = 1 == this.haveNewObstce ? 1 : 2;
                this.showOneRadio(this.newObstacleNode, "option_" + r);
            }
            0 == o.guideIndex ? this.guideIndexEdit.getComponent(cc.EditBox).string = "" : this.guideIndexEdit.getComponent(cc.EditBox).string = o.guideIndex + "";
            this.recoveryBottomBg();
            this.recoveryLowest();
            this.recoveryMiddle();
            this.recoveryTop();
            this.recoveryProbabilityDrop();
            this.recoveryTag();
            this.fixedRefreshNode.getComponent(B).recover();
        } else u.log("恢复的数据不存在");
    };
    public recoveryBottomBg() {
        for (var e = L.initGameInfo.mapArr, t = 0; t < e.length; t++) for (var a = e[t], o = 0; o < a.length; o++) {
            var i = a[o], r = this.getBottomCNode(t, o);
            2 != i && 3 != i || r.sitCanPlaceState(i);
        }
    };
    public recoveryLowest() {
        for (var e = L.initGameInfo.bottomSquareData, t = 0; t < e.length; t++) for (var a = e[t], o = 0; o < a.length; o++) {
            var i = a[o];
            if ("N" != i) {
                this.createEditorBottomSquareItem(t, o, i, this.lowestParent);
                var r = this.lowestParent.children.length - 1, n = this.lowestParent.children[r];
                if (!n) {
                    u.log("底层没有添加上子节点请检查");
                    return;
                }
                n.name = "lowestLayer_" + t + "_" + o;
            }
        }
    };
    public recoveryMiddle() {
        for (var e = L.initGameInfo.middleSquareData, t = 0; t < e.length; t++) for (var a = e[t], o = 0; o < a.length; o++) {
            var i = a[o];
            if ("N" != i && "E" != i) {
                var r = i[0];
                if (r == T.SquareType.MatchItem || r == T.SquareType.PropItem) {
                    this.createEditorMiddleSquareItem(t, o, i, this.middleParents);
                    var n = this.middleParents.children.length - 1, l = this.middleParents.children[n];
                    if (!l) {
                        u.log("中层没有添加上子节点请检查");
                        return;
                    }
                    var s = l.getComponent(m), c = l.getComponent(v);
                    s && l.removeComponent(m);
                    c && l.removeComponent(v);
                    l.name = "middleLayer_" + t + "_" + o + "-" + i;
                } else if (r == T.SquareType.ObstacleItem) {
                    this.createEditorMiddleSquareItem(t, o, i, this.middleParents);
                    n = this.middleParents.children.length - 1;
                    var p = this.middleParents.children[n];
                    if (!p) {
                        u.log("中层没有添加上障碍物节点请检查");
                        return;
                    }
                    p.getComponent(_) && p.removeComponent(_);
                    p.name = "middleLayer_" + t + "_" + o + "-" + i;
                }
            }
        }
    };
    public recoveryTop() {
        for (var e = L.initGameInfo.topSquareData, t = 0; t < e.length; t++) for (var a = e[t], o = 0; o < a.length; o++) {
            var i = a[o];
            if ("N" != i && "E" != i) {
                this.createEditorTopSquareItem(t, o, i, this.topParents);
                var r = this.topParents.children.length - 1, n = this.topParents.children[r];
                if (!n) {
                    u.log("顶层没有添加上障碍物节点请检查");
                    return;
                }
                n.getComponent(_) && n.removeComponent(_);
                n.name = "topLayer_" + t + "_" + o + "-" + i;
            }
        }
    };
    public showTargetInfo;
    public bottomrefreshTargrtInfo;
    public recoveryTag() {
        var e = L.initGameInfo.targetMatchData;
        this.bottomrefreshTargrtInfo = [];
        this.showTargetInfo = [];
        for (var t = 0; t < e.length; t++) {
            var a = e[t];
            if (a.squareType == s.MatchItem) {
                (o = cc.instantiate(this.targetPrefab)).getChildByName("input_count").getComponent(cc.EditBox).string = a.tootalCount + "";
                o.getComponent(F).init({
                    squareType: s.MatchItem,
                    itemType: a.itemType,
                    tootalCount: a.tootalCount
                });
                this.showTargetInfo.push({
                    targetSquareType: s.MatchItem,
                    itemType: a.itemType,
                    targetCount: a.tootalCount
                });
                this.tagSetNode.addChild(o);
            } else if (a.squareType == s.ObstacleItem) {
                var o;
                (o = cc.instantiate(this.targetPrefab)).getChildByName("input_count").getComponent(cc.EditBox).string = a.tootalCount + "";
                o.getComponent(F).init({
                    squareType: s.ObstacleItem,
                    itemType: a.itemType,
                    tootalCount: a.tootalCount
                });
                this.showTargetInfo.push({
                    targetSquareType: s.ObstacleItem,
                    itemType: a.itemType,
                    targetCount: a.tootalCount
                });
                this.tagSetNode.addChild(o);
                if (-1 !== j.indexOf(a.itemType)) {
                    var i, r = cc.instantiate(this.targetPrefab), n = L.isNewProbabilityDrop(), l = a.itemType, c = a.squareTypeStr;
                    if (!c) {
                        var u = 0;
                        l == ObstacleAllType.Egg ? u = 1 : l == ObstacleAllType.Vase ? u = 2 : l == ObstacleAllType.Oyster ? u = 2 : l == ObstacleAllType.Flowerpot ? u = 2 : l == ObstacleAllType.PorcelainPig ? u = 1 : l == ObstacleAllType.GoldCoin && (u = 1);
                        c = "O-" + a.itemType + "_" + u;
                    }
                    i = n ? this.getPercentageByType(null, null, c) : this.getPercentageByType(s.ObstacleItem, a.itemType, null);
                    r.getChildByName("input_count").getComponent(cc.EditBox).string = i + "";
                    r.getComponent(F).init({
                        squareType: s.ObstacleItem,
                        itemType: a.itemType,
                        tootalCount: a.tootalCount,
                        squareTypeStr: c
                    });
                    this.bottomrefreshTargrtInfo.push({
                        targetSquareType: s.ObstacleItem,
                        itemType: a.itemType,
                        targetCount: a.tootalCount
                    });
                    this.pRefreshSitNode.addChild(r);
                }
            }
            this.updateTagItemPos(this.tagSetNode);
            this.updateTagItemPos(this.pRefreshSitNode);
        }
    };
    public recoveryProbabilityDrop() {
        for (var e = L.initGameInfo.probabilityDropData, t = this.elementPropsNode.children, a = 0; a < t.length; a++) for (var o = t[a], i = o.getChildByName("input_count"), r = o.getComponent(F), n = 0; n < e.length; n++) {
            var l = e[n].squareTypeStr, s = e[n].squareType, c = e[n].itemType;
            if (l) {
                s = (l = l.split("-"))[0];
                c = parseInt(l[1]);
                "M" == s ? s = 1 : "P" == s && (s = 2);
            }
            var u = e[n].precentNumber;
            r.squareType == s && (1 == r.squareType && r.matchType == c ? i.getComponent(cc.EditBox).string = u + "" : 2 == r.squareType && r.propType == c && (i.getComponent(cc.EditBox).string = u + ""));
        }
    };
    public getPercentageByType(e, t, a) {
        for (var o = L.initGameInfo.probabilityDropData, i = L.isNewProbabilityDrop(), r = 0; r < o.length; r++) {
            var n = o[r], l = n.squareTypeStr;
            if (i) {
                u.log("squareTypeStr", l);
                u.log("sTypeStr", a);
                if (l && -1 != l.indexOf(a)) return n.precentNumber;
            } else if (n.squareType == e && n.itemType == t) return n.precentNumber;
        }
        return 0;
    };
    public removeEvent() { };
    public start() { };
}


